export const weeks = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
import { holidays,holidayName } from '@/common/static.object.js'
export function monthDays(year,month){
    const date = new Date(year,month)
    let firstWeek = new Date(date.getFullYear(), date.getMonth(), 1).getDay()
    if(firstWeek === 0){
        firstWeek = 7
    }
    let max = new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate()
    let beforeMax = new Date(date.getFullYear(), date.getMonth(), 0).getDate()
    const dayArrays = []
    for (let i = firstWeek - 2; i >= 0; i--) {
        dayArrays.push({
            type: 'before',
            month:month,
            year:year,
            day: beforeMax - i
        })
    }
    for (let i = 1; i <= max; i++) {
        dayArrays.push({
            type: 'now',
            month:month+1,
            year:year,
            day: i
        })
    }
    let i = 1
    while (dayArrays.length < 42) {
        dayArrays.push({
            type: 'after',
            month:month+2,
            year:year,
            day: i++
        })
    }

    for(let i=0;i<dayArrays.length;i++){
        debugger
        let day = dayArrays[i]['day']
        let m = dayArrays[i]['month']
        let y = dayArrays[i]['year']

        try{
            let work = holidays[y][m]['work']
            let holiday = holidays[y][m]['holiday']
            if(work.indexOf(day) >-1){
                dayArrays[i]['work'] = 1
            }
            if(holiday.indexOf(day) >-1 ){
                dayArrays[i]['holiday'] = 1
                dayArrays[i]['holidayName']=holidayName[y][m][day]
            }

        }catch (err){
            console.log(err)
        }

    }




    const array = []
    array.push(dayArrays.slice(0, 7))
    array.push(dayArrays.slice(7, 14))
    array.push(dayArrays.slice(14, 21))
    array.push(dayArrays.slice(21, 28))
    array.push(dayArrays.slice(28, 35))
    array.push(dayArrays.slice(35, 42))
    return array
}